package com.cdvtc.news.service.impl;

import com.cdvtc.news.dao.UserDao;
import com.cdvtc.news.entity.User;
import com.cdvtc.news.service.UserService;
import com.cdvtc.news.util.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User login(String account, String password) {
        return userDao.login(account, Md5Util.md5(password)); // 注意：密码需要先进行MD5加密
    }

    @Override
    public Boolean isUserExisted(String key, String value) {
        return userDao.isUserExisted(key, value);
    }

    @Override
    public boolean addUser(User user) {
        user.setPassword(Md5Util.md5(user.getPassword())); //密码使用MD5加密保存
        return userDao.addUser(user);
    }

    @Override
    public List<User> getAllUsers() {
        return userDao.getAllUsers();
    }

    @Override
    public void forbiddenUser(int userId, boolean forbidden) {
        userDao.forbiddenUser(userId, forbidden);
    }
}
